<template>
    <div class="app-container"
         v-loading.fullscreen.lock="allLoading"
         element-loading-text="拼命处理中,请耐心等待"
         element-loading-spinner="el-icon-loading"
         element-loading-background="rgba(0, 0, 0, 0.8)"
    >
        <el-dialog :close-on-click-modal="changeBitFlagIsNone" :title="mainDialogInfo.title" :visible.sync="showDialog"
                   width="50%" append-to-body @close="closeDialog">
            <el-form ref="form" :disabled="changeBitFlagIsNone" :model="form" :rules="rules" label-width="120px">
                <el-form-item prop="description" label="描述">
                    <el-input   v-model="form.description"  placeholder="请输入" />
                </el-form-item>
                <el-form-item prop="remark" label="备注">
                    <el-input   v-model="form.remark"  type="textarea"  placeholder="请输入" />
                </el-form-item>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <template v-if="!changeBitFlagIsNone">
                    <el-button type="primary" @click="submitMainDialog">确 定</el-button>
                </template>
                <el-button @click="cancelMainDialog">关 闭</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import {sksDialogFormMixin} from "/lib/dialog-form";

export default {
    name: "Dialog40",
    mixins: [
        sksDialogFormMixin,
    ],
    data() {
        return {
            defaultForm: {
                id: undefined,
                //描述
                description: undefined,
                //备注
                remark: undefined,
            },
            defaultFormNotNull: {
                virtualDocumentList: [],
            },

            rules: {
                description: [
                    {required: true, message: '不能为空', trigger: "blur"},
                ],
            },
        };
    },
    methods:{
        showByUniqueId({uniqueId,extra,dialogInfo,virtualChangeBitFlag=this.sksUtils.CHANGE_BIT_FLAG.none}){
            let data={
                id: 1,
                description: '蒋校长',
                remark: '这是测试数据'
            }
            this.show({
                extra: extra,
                form: this.sksUtils.mergeFromObject({},data,{
                    virtualChangeBitFlag: virtualChangeBitFlag,
                }),
                dialogInfo: dialogInfo
            })
        },
        validateSuccess() {
            let data = this.sksUtils.mergeFromObject({}, this.form);

            if (!this.sksUtils.isNullOrUndefined(this.mainDialogInfo.submitCallback)) {
                this.mainDialogInfo.submitCallback({submitData: data, ref: this})
                //this.showDialog=false
                return
            }
            switch(data.virtualChangeBitFlag) {
                case this.sksUtils.CHANGE_BIT_FLAG.add:
                    this.closeDialog()
                    this.sksUtils.msgSuccess("新增成功");
                    //此处换成新增接口 start
                    //新增接口返回新增后的数据
                    let saRes={
                        data: this.sksUtils.mergeFromObject({},data,{
                            id: 1000,
                        })
                    }
                    //此处换成新增接口 end
                    if (!this.sksUtils.isNullOrUndefined(this.mainDialogInfo.submitCallbackSuccess)){
                        this.mainDialogInfo.submitCallbackSuccess({resData: saRes.data})
                    }
                    break;
                case this.sksUtils.CHANGE_BIT_FLAG.modify:
                    this.closeDialog()
                    this.sksUtils.msgSuccess("修改成功");
                    if (!this.sksUtils.isNullOrUndefined(this.mainDialogInfo.submitCallbackSuccess)){
                        this.mainDialogInfo.submitCallbackSuccess({resData: data})
                    }
                    break;
                default:
                    this.sksUtils.msgError("未知的变更标识");
                    break;
            }
        },
    }
}
</script>

<style scoped>

</style>
